package com.jiangjiang.eshop.membership.controller;

import com.jiangjiang.eshop.membership.biz.UserAccountBiz;
import com.jiangjiang.eshop.membership.dto.UserAccountDTO;
import com.jiangjiang.eshop.membership.dto.PasswordUpdateDTO;
import com.jiangjiang.eshop.membership.dto.UserLoginDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName UserAccountController
 * @Description TODO
 * @Author jhw
 * @Date 2021/8/21 12:41
 * @Version 1.0
 **/
@Slf4j
@RestController
@RequestMapping("/user/account")
public class UserAccountController {
    @Autowired
    private UserAccountBiz biz;
    /**
     * 用户注册
     * @param dto 入参
     * @return 处理结果
     */
    @PostMapping("/register")
    public Boolean register(@RequestBody  UserAccountDTO dto){
        try {
          return  biz.saveUserAccount(dto);
        }catch (Exception e){
            log.warn("UserAccountController saveUserAccount error",e);
        }
        return false;
    }

    /**
     * 用户登录
     * @param dto 登录入参
     * @return 处理结果
     */
    @PostMapping("/login")
    public UserAccountDTO login(@RequestBody UserLoginDTO dto){
        try {
            return  biz.login(dto);
        }catch (Exception e){
            log.warn("UserAccountController login error",e);
        }
        return null;
    }


    /**
     * 更新密码
     * @param dto
     * @return
     */
    @PostMapping("/updatePassword")
    public Boolean updatePassword(@RequestBody PasswordUpdateDTO dto){
        try {
            return biz.updatePassword(dto);
        }catch (Exception e){
            log.warn("UserAccountController updatePassword error",e);
        }
        return false;
    }

}
